package org.zjx.dao.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("开始插入填充...");
        // 起始版本 3.3.3(推荐)
        this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now());
        // Date类型填充
        //this.strictInsertFill(metaObject, "createTime", () -> new Date(), Date.class);
        // 起始版本 3.3.0(推荐使用)
        //this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now());
        // 也可以使用(3.3.0 该方法有bug)
        //this.fillStrategy(metaObject, "createTime", LocalDateTime.now());
    }
    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("开始更新填充...");
        // 起始版本 3.3.3(推荐)
        this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
        // Date类型填充
        //this.strictUpdateFill(metaObject, "updateTime", Date::new, Date.class);
        // 起始版本 3.3.0(推荐)
        //this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
        // 也可以使用(3.3.0 该方法有bug)
        //this.fillStrategy(metaObject, "updateTime", LocalDateTime.now()); // 也可以使用(3.3.0 该方法有bug)
    }
}